package com.tdx.blog_nowcoder.utils;

import com.tdx.blog_nowcoder.entity.User;
import org.springframework.stereotype.Component;

@Component
public class ThreadHostHolder {
    private ThreadLocal<User> users = new ThreadLocal<>();
    ThreadLocal<User> u2 = ThreadLocal.withInitial(()->null);

    ThreadLocal<User> u3 = new ThreadLocal<User>(){
        @Override
        protected User initialValue() {
            return super.initialValue();
        }
    };


    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }
}
